#pragma once
#include <iostream>
#include "BTree.h"

template <class K,class V,size_t M = 1024>
class BTreeMap
{
	struct MapKofT
	{
		const K& operator()(const std::pair<const K, V>& kv)
		{
			return kv.first;
		}
	};
	typedef BTree::BT<std::pair<K, V>, MapKofT, M> BTNode;
	typedef typename BTNode::iterator iterator;
public:
	iterator begin()
	{
		return _bt.begin();
	}


	std::pair<std::pair<K, V>, bool> Find(const K& key)
	{
		//std::pair<std::pair<BN, size_t>,bool>
		//std::pair<T, std::shared_ptr<BNode>>
		auto it = _bt.Find({ key,V() });
		bool sig = false;
		auto bn = it.first.first;
		size_t pos = it.first.second;
		if (it.second && bn->_exist[pos])sig = true;
		return { bn->_BN[pos].first,sig };
	}
	bool insert(const std::pair<K, V>& kv)
	{
		return _bt.insert(kv);
	}
	void Print()
	{
		_bt.Print();
	}
	bool erase(const K& key)
	{
		return _bt.erase({key,V()});
	}
private:
	BTNode _bt;
};